# Maintainer: Filipe Laíns (FFY00) <lains@archlinux.org>

_prj=trellis
pkgname=prj$_prj
pkgver=1.4
pkgrel=1
pkgdesc='Documentation and definitions for the Lattice ECP5 bit-stream format'
arch=('loong64' 'x86_64')
url='https://github.com/YosysHQ/prjtrellis'
license=('custom:ISC' 'MIT')
depends=('boost-libs')
makedepends=('cmake' "$pkgname-db" 'boost' 'python')
optdepends=('python: Python support')
provides=('libtrellis')
conflicts=('libtrellis')
source=("$pkgname-$pkgver.tar.gz::$url/archive/$pkgver.tar.gz")
sha512sums=('3fd8bf533da98f3cdf6a0fe92ee4b2cb5d58fcc568e3365a1927fae392a4aaeec80b1f53e26ccd6c7afd7efb17b749cd8bac6d3ec2d17f9ad2c33da592a213d9')

prepare() {
  cd $pkgname-$pkgver

  sed -i 's|set(LIBDIR "lib64")|set(LIBDIR "lib")|
          s|project(libtrellis)|project(libtrellis VERSION 1.0)|' libtrellis/CMakeLists.txt
}

build() {
  mkdir $pkgname-$pkgver/libtrellis/build
  cd $pkgname-$pkgver/libtrellis/build

  cmake .. \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_INSTALL_LIBDIR=/lib \
    -DCMAKE_BUILD_TYPE=Release

  sed -i '/Boost::python-NOTFOUND/d' CMakeFiles/*.dir/build.make
  sed -i 's|Boost::python-NOTFOUND||g' CMakeFiles/*.dir/link.txt

  make
}

package() {
  cd $pkgname-$pkgver

  install -Dm 644 COPYING "$pkgdir"/usr/share/licenses/$pkgname/LICENSE

  cd libtrellis/build

  make DESTDIR="$pkgdir" install

  mv "$pkgdir"/lib "$pkgdir"/usr/lib

  # The database is provided in a separate package
  rmdir "$pkgdir"/usr/share/$_prj/database
}
